package com.yami.shop.platform.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.BusinessNft;
import com.yami.shop.bean.model.ShopDetail;
import com.yami.shop.bean.model.UserAirdrop;
import com.yami.shop.bean.param.SendUserDropsParam;
import com.yami.shop.bean.param.UserUpdateParam;
import com.yami.shop.common.config.Constant;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.service.BusinessNftService;
import com.yami.shop.service.UserAirdropService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminUserAirdropController")
@RequestMapping("/platform/airdrop")
@Tag(name = "平台端空投接口")
@Slf4j
public class UserAirdropController {


    @Autowired
    private BusinessNftService businessNftService;

    @Autowired
    private UserAirdropService userAirdropService;

    @PutMapping("/sendUserDrop")
    @PreAuthorize("@pms.hasPermission('platform:drop:sendUserDrop')")
    @Operation(summary = "平台批量空投艺术品或盲盒给会员")
    public ServerResponseEntity<Boolean> sendUserDrop(@RequestBody UserUpdateParam param) {
        List<String> userIds = param.getUserIds();
        if (CollectionUtils.isEmpty(userIds)) {
            return ServerResponseEntity.success();
        }

        List<SendUserDropsParam> drops = param.getDrops();
        if (CollectionUtils.isEmpty(drops)) {
            return ServerResponseEntity.success();
        }
        ShopDetail detail = new ShopDetail();
        detail.setShopId(Constant.PLATFORM_SHOP_ID);
        param.setBusinessType(1);
        businessNftService.bindDropById(param, detail);
        return ServerResponseEntity.success();
    }

    @GetMapping("/page")
    @Operation(summary = "分页获取用户空投列表信息", description = "分页获取用户空投列表信息")
    public ServerResponseEntity<IPage<UserAirdrop>> page(@ParameterObject UserAirdrop userAirdrop, PageParam<UserAirdrop> page) {
        IPage<UserAirdrop> userDropPage = userAirdropService.getUserAirdropPage(page, userAirdrop);
        return ServerResponseEntity.success(userDropPage);
    }

}
